{include file='fcworker/fc_userdata_head'}
	<style>
		.jourSearch .layui-form {
			float: left;
			width: 2.3rem;
			background: #f3f3f3;
			height: .62rem;
			padding: 0.1rem 0.2rem;
			border-radius: .62rem;
		}
		.jourSearch .layui-inline {
			height: 100%;
		}
		.jourSearch .layui-form-select {
			height: 100%;
		}
		.jourSearch .layui-select-title {
			height: 100%;
		}
		.jourSearch .layui-form .layui-form-select .layui-input {
			background: transparent;
			height: 100%;
			border: none;
		}
		.jourSearch .layui-form .layui-form-select dl {
			top: .62rem;
			left: -0.2rem;
		}
		.jourSearch .layui-form .layui-form-select dl dd.layui-this {
			background-color: #70b6f7;
		}
	</style>
<div id="mescroll" class="mescroll">
	<div class="app">
		<div class="fixTop">
			<div class="journalTitle">
				<a class="cur" href="/{php echo createMobileUrl('main',array('themeid'=>$themeid,'mod'=> 'userdata','op' => 'log_list'));}" >日志</a>
				<a href="/{php echo createMobileUrl('main',array('themeid'=>$themeid,'mod'=> 'userdata','op' => 'focuse_list'));}">关注</a>
				<a href="/{php echo createMobileUrl('main',array('themeid'=>$themeid,'mod'=> 'userdata','op' => 'trace_list'));}">追踪</a>
			</div>
			<div class="jourSearch">
				{if $level<3}
				<div class="layui-form">
					<div class="layui-inline">
						<select name="select_workerid" lay-verify="" id="select_workerid">
							<option value ="0" >所有员工</option>
							{loop  $worker_list  $val}
							<option value ="{$val['uid']}" >{$val['username']}</option>
							{/loop}
						</select>
					</div>
				</div>
				{/if}
				<input type="text"  name="keyword" id="keyword" value="{$keyword}" placeholder="输入客户昵称或姓名"/>
				<button type="button" id="search_btn">搜索</button>
			</div>
		</div>
		<div class="h203">

		</div>
		<div class="journalList">
			<ul id="newsList"  class="news-list">
			</ul>
		</div>
	</div>

	<input type="hidden" name="page" id="page" value="1">
	<input type="hidden" name="op" id="op" value="log_list">
	<input type="hidden" name="hasNext" id="hasNext" value="{$hasNext}">
	<div style="height: 1.1rem;"></div>
	</div>
</div>
 </body>
<script type="text/javascript" charset="utf-8">
	const mescroll = new MeScroll("mescroll", {
		down: {
			auto: false,
			callback: () => {
				mescroll.endSuccess();
				// setTimeout(() => {
				// 	window.location.reload();
				// },500)
				getData(1,() => {
					mescroll.endSuccess()
				},true)
			}
		},
		up: {
			use: true,
			auto: false,
			isBounce: false,
			callback: (page) => {
				let pageNum = Number($("#page").val())+1;
				getData(pageNum, (curPageData, hasNext) => {
					mescroll.endSuccess(curPageData, hasNext);
				});
			}
		}
	})
	// if(!$("#hasNext").val()) {
	// 	mescroll.lockUpScroll(true);
	// }
	var loadingState= false;
	var hasNext = 1;
	$('#search_btn').click(function(){
		sessionStorage.removeItem('journal_page_list');
		var select_workerid = {php echo $select_workerid ? $select_workerid : 0;};
		var keyword = $('#keyword').val();
		location.href = "/{php echo createMobileUrl('main',array('themeid'=>$themeid,'mod'=> 'userdata','op' => $op));}&select_workerid="+select_workerid+"&keyword="+keyword;
	})

	$('#newsList').on('click','.controlBar > i',function(event){
		event.stopPropagation();
		$(".controlList").hide();
		if ($(this).prev().is(':hidden')) {
			$(this).prev().show();
		}else{
			$(this).prev().hide();
		}
	});
	$(document).on("click",function(){
		$(".controlList").hide();
	});
	$('#mescroll').scroll(function() {
		const scrollSpace = $(this).scrollTop()
		sessionStorage.setItem("journal_offset_top",scrollSpace);//保存滚动位置
	})

	window.onload = function()
	{
		//var pageIndex = sessionStorage.getItem("pageIndex");
		var pageList = sessionStorage.getItem("journal_page_list");
		if(pageList!=null){
			$("#newsList").html(pageList);
			var hasNext = sessionStorage.getItem("journal_has_next");
			$("#hasNext").val(hasNext);
			var offset = sessionStorage.getItem("journal_offset_top");
			$('#mescroll').scrollTop(offset);
			$("#page").val(sessionStorage.getItem("journal_page_index"));

			if(sessionStorage.getItem("journal_select_workerid")!=null){
				$('#select_workerid').val(sessionStorage.getItem("journal_select_workerid"));
			}

			if(sessionStorage.getItem("journal_keyword")){
				$('#keyword').val(sessionStorage.getItem("journal_keyword"));
			}

			//sessionStorage.removeItem('journal_page_list');
			//sessionStorage.removeItem('journal_offset_top');
		}else{
			var page = $("#page").val();
			getData(page);
		}
	};


	// $(function(){
	//
	// });

	// $(window).scroll(function(){
	// 	hasNext = $("#hasNext").val();
	// 	var height = $(window).height();
	// 	var scrollSpace = $(window).scrollTop();
	// 	if(scrollSpace>height){
	// 		$('.backTop').fadeIn();
	// 	}else{
	// 		$('.backTop').fadeOut();
	// 	}
	// 	sessionStorage.setItem("journal_offset_top",scrollSpace);//保存滚动位置
	// 	if (scrollSpace >= $(document).height() -  (height*1.2)){
	// 		 if (!loadingState && hasNext==1){
	// 			layer.msg('加载中', {
	// 				icon: 16
	// 				,shade: 0.01
	// 			});
	// 			//getData(hasNext)
	// 			var page = $("#page").val();
	// 			var next_page = +page+1;
	// 			getData(next_page)
	// 		 }
	// 	}
	// })

	function  getData(page, cb,isRefresh = false){
		$("#page").val(page);
		var select_workerid = {php echo $select_workerid ? $select_workerid : 0;};
		var keyword = $("#keyword").val();
		var op = $("#op").val();
		loadingState = true;
		var postUrl="/{php echo  createMobileUrl('main',array('themeid'=>$themeid,'mod'=> 'userdata'));}";
		$.ajax({
			url:postUrl,
			dataType:'json',
			method:'post',
			data: {op:op,page:page,select_workerid:select_workerid,keyword:keyword,is_refresh:isRefresh},
			success:function (e) {
				let data = e.data.res_list;
				let error = e.error;
				let msg = e.msg;
				if (error!=0){
					layer.msg(msg);
					return false;
				}
				var curPageData = data.curPageData;
				var hasNext = data.hasNext;
				var is_refresh  = data.is_refresh;
				// if(is_refresh==1&&curPageData.length==0){
				// 	console.log('无更新');
				// 	return  false;
				// }

				setListData(curPageData, !isRefresh);
				layer.closeAll();
				if(cb && typeof cb == 'function') {
					cb(curPageData.length, hasNext)
				}

				loadingState = false;
				if (data.hasNext){
					hasNext = 1;
				}else{
					hasNext = 0;
				}
				console.log('start session')
				sessionStorage.setItem('journal_page_index',page);
				sessionStorage.setItem('journal_loading_state',loadingState);
				sessionStorage.setItem('journal_has_next',hasNext);
				setTimeout(() => {
					sessionStorage.setItem('journal_page_list',$('#newsList').html());
				},200)
				if(select_workerid>0){
					sessionStorage.setItem('journal_select_workerid',select_workerid);
				}else{
					sessionStorage.removeItem('journal_select_workerid')
				}

				if(keyword!=''){
					sessionStorage.setItem('journal_keyword',keyword);
				}else{
					sessionStorage.removeItem('journal_keyword')
				}
				$("#hasNext").val(hasNext);
			},
			fail:function (err) {
				console.log(err)
			}
		});
	}

	layui.use('form', function(){
		const form = layui.form;
		var op = $('#op').val()
		var select_workerid = {php echo $select_workerid?$select_workerid:0;};
		form.on('select', function (data) {
			sessionStorage.removeItem('journal_page_list');
			sessionStorage.removeItem('journal_offset_top');
			location.href = `/{php echo createMobileUrl('main',array('themeid'=>$themeid,'mod'=> 'userdata'));}&op=${op}&select_workerid=${data.value}`;
		})
		$('#select_workerid').val(select_workerid)
		form.render();
	});

</script>
{include file='fcworker/fc_userdata_setList'}
{if $system['h5work'] == '1'}
{include file='fcworker/fc_foot'}
{else}
{include file='yxworker/w_head'}
{/if}